package engine

type ParserResult struct {
	Requests []Request
	Items    []Item
}

type Item struct {
	Url     string
	Type    string
	Id      string
	Payload interface{}
}

type Request struct {
	URL    string
	Parser Parser
}

type Parser interface {
	Parse([]byte) ParserResult
	Serialize() (name string, args interface{})
}

type FuncParser struct {
	ParserFunc func([]byte) ParserResult
	Name       string
	Args       interface{}
}

func (p *FuncParser) Parse(content []byte) ParserResult {
	return p.ParserFunc(content)
}

func (p *FuncParser) Serialize() (name string, args interface{}) {
	return p.Name, p.Args
}

func NewFuncParser(f func([]byte) ParserResult,
	name string, args interface{}) FuncParser {
	return FuncParser{
		ParserFunc: f,
		Name:       name,
		Args:       args,
	}
}

func NilParser([]byte) ParserResult {
	return ParserResult{}
}
